﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using WPFDataEditors.ProgressBar.Control;

namespace WPFDataEditors.ProgressBar.Converter
{
    internal class ProgressBarContentConverter:IMultiValueConverter
    {
      
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if(values[0]==DependencyProperty.UnsetValue || 
               values[1]==DependencyProperty.UnsetValue ||
               values[2]==DependencyProperty.UnsetValue||
               values[3]==DependencyProperty.UnsetValue
               )
                return "";
            var value = System.Convert.ToDouble(values[1]);
            var maximum = System.Convert.ToDouble(values[0]);
            var type = (ProgressBarType)values[3];
            var content = System.Convert.ToString(values[2]);
            switch (type)
            {
                case ProgressBarType.None:
                    return "";
                case ProgressBarType.Content:
                    return content;
                case ProgressBarType.Value:
                    return Math.Round(value, 2).ToString(CultureInfo.InvariantCulture);
                case ProgressBarType.Ratio:
                    return Math.Round(value,2).ToString(CultureInfo.InvariantCulture) + "/" + maximum.ToString(CultureInfo.InvariantCulture);
                case ProgressBarType.Percentage:
                    var percentage = Math.Round(value * 100 / maximum, 2);
                    return percentage + "%";
                default:
                    return "";

            }

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
